﻿using APPWG4806.Back.Entry;
using DevExpress.XtraEditors;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;

namespace APPWG4806.View
{
    public partial class BadReportForm : DevExpress.XtraEditors.XtraForm
    {

        private List<BadTypeEntry> badTypeEntries = new List<BadTypeEntry>();

        public BadReportForm()
        {
            InitializeComponent();
            // 窗口居中设置
            this.StartPosition = FormStartPosition.CenterScreen;
        }

        private void BadReportForm_Load(object sender, EventArgs e)
        {
            string json = "";
            try
            {
                json = HttpHelp.GetData("http://localhost:9081/LH_ErrorType/GetData", null);
                badTypeEntries = JsonConvert.DeserializeObject<List<BadTypeEntry>>(json);
            }
            catch (Exception)
            {
                MessageBox.Show("API连接错误");
                return;
            }
            
            BadType_CB.DataSource = badTypeEntries;
            BadType_CB.DisplayMember = "ErrorTypeName";
            BadType_CB.ValueMember = "ID";
            BadType_CB.SelectedIndex = -1;
        }
        /// <summary>
        /// 取消按钮操作
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Relese_BT_Click(object sender, EventArgs e)
        {
            // 清空SN输入框
            SN_TB.Text = "";
            // 清空不良类型选择框
            BadType_CB.SelectedIndex = -1;
        }

        private void Submit_BT_Click(object sender, EventArgs e)
        {
            string snText = SN_TB.Text;
            if (string.IsNullOrWhiteSpace(snText))
            {
                MessageBox.Show("SN条码不能为空");
                return;
            }
            int selectIndex = BadType_CB.SelectedIndex;
            if (selectIndex<0)
            {
                MessageBox.Show("请选择错误类型");
                return;
            }
            if (selectIndex < 0)
            {
                
            }


            //TODO 未做不良汇报提交验证
            string res = HttpHelp.GetData("http://localhost:9081/LH_ReSnInfo/GetRsSnCount?sn="+SN_TB.Text.Trim(), null);


            MessageBox.Show("提交成功");
            this.Close();
        }
    }
}